package conexao;

import java.io.IOException;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Player;

import jmapps.util.StateHelper;

import audio.MicrofoneAusenteException;

public class ClienteRTP extends Thread {
	
	private MediaLocator fonte;
	private Player tocador;

	public ClienteRTP(String ipFonte, int porta) {
			String url = "rtp://"+ipFonte+":"+porta+"/audio/1";
	    	this.fonte = new MediaLocator(url);	 
	    	System.out.println(url);
	}	
	
	public MediaLocator getFonte() {
		return fonte;
	}

	public void setFonte(MediaLocator fonte) {
		this.fonte = fonte;
	}

	public Player getTocador() {
		return tocador;
	}

	public void setTocador(Player tocador) {
		this.tocador = tocador;
	}

	public void receber() throws NoPlayerException, IOException{
		if(this.fonte == null){
			System.err.println("N�o localizou o local do RTP Stream");
		}
		this.tocador = Manager.createPlayer(fonte);
		StateHelper sh = new StateHelper(this.tocador);
		//configura o player para realize
		if(!sh.realize(100000)){
			System.out.println("estourou o tempo.");
		}
		this.tocador.start();
	}

	@Override
	public void run() {
		try {
			this.receber();
		} catch (NoPlayerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
public static void main(String[] args){    	
			ClienteRTP teste2;	
			teste2 = new ClienteRTP("172.16.1.209", 5000);
			teste2.start();		
    }

}
